// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import Game from "./game";

const {ccclass, property} = cc._decorator;

@ccclass
export default class BulletScript extends cc.Component {
    
    step: number = 6;
    canvasHeight: number = 0;
    

    onLoad () {
        this.canvasHeight = cc.find('Canvas').height;
    }

    start () {

    }

    update (dt) {
        this.node.y += this.step;

        if(this.node.y >= this.canvasHeight){
            this.dismist()
        }
    }

    dismist(){
        // 销毁子弹
        // this.node.removeFromParent() // 对象池的put方法内部会调用此函数，所以这里不需要再次调用了
        // this.node.destroy()
        
        Game.bulletPool.put(this.node)
    }

    
}
